clear all 
set more off
cd "/gpfs/home/kmd86/LFS/PublicFilesCode_QJER2/Cleaned_ForDropbox/"

* tenure/experience profiles


* graph colors/sizes
set autotabgraphs on

local msize1 "medsmall"
local msize2 "medlarge"

local color1 "0 76 167"
local color2 "146 0 0"
local color3 "62 150 81"
local colorgb "white"

local color1b "0 76 167"
local color2b "146 0 0"
local color3b "62 150 81"

* load
use "Tenure_Exper_WageProfiles.dta", clear 

* alternative averages
bys ccode tbin: egen dat2 = mean(dt)
bys ccode ebin: egen dae2 = mean(de)

* make graphs
set autotabgraphs on

* counter to get the averages right on the graphs
sort ccode year ebin
by ccode: gen counter = _n
replace counter = . if counter > 6
replace counter = 1 if !missing(counter)

* average income
bys ccode: egen mean_AGDP = mean(AGDP)

* graphs below:


* an appendix table read directly from the results window in Stata
gen dt55 = dt / 100
reg dt55 i.tbin i.tbin#c.lcgdp if tbin >= 2, cluster(ccode)
test _b[2.tbin#c.lcgdp] == _b[3.tbin#c.lcgdp]
test _b[2.tbin#c.lcgdp] == _b[4.tbin#c.lcgdp]
test _b[3.tbin#c.lcgdp] == _b[4.tbin#c.lcgdp]




* Tenure graphs
forvalues ii = 2/3{
	
	if `ii' == 2 {
		local bn "2_612m"
	}
	if `ii' == 3 {
		local bn "3_15y"
	}
	if `ii' == 4 {
		local bn "4_5py"
	}	
	
	#delimit ;

	* trendlines;
	reg dt lcgdp if tbin == `ii';
	predict trend_t;

	* tenure ;
	twoway(scatter dt AGDP, mcolor("`color1b'%10") msize(`msize1')  msymbol(O) mlwidth(none)) 
	(line trend_t AGDP, lcolor(gs6) lwidth(thin) alc(background)) 
	(scatter dat2 mean_AGDP if counter == 1, mcolor("`color1'") msize(`msize2') mlabel(ccode) msymbol(O) mlabcolor("`color1'")) 
	if tbin == `ii' & dt >= 0, name(WageGrowth_t`ii') legend(off) graphregion(color("`colorgb'")) xtitle("GDP per capita") 
	yscale(r(0 60)) ylabel(0(10)60) xscale(log) xlabel(4000 8000 16000 32000 64000);	
	#delimit cr

	if `ii' <= 3 {
		graph export "Figures/Figure8_TenureBin`bn'.tif", replace
		graph export "Figures/pdf_figures/Figure8_TenureBin`bn'.pdf", replace
		
	}
	drop trend_t
}



* EXPERIENCE GRAPHS
forvalues ii = 5/6 {
	
	if `ii' == 2 {
		local bn "2_12y"
	}
	if `ii' == 3 {
		local bn "3_25y"
	}
	if `ii' == 4 {
		local bn "4_510y"
	}	
	if `ii' == 5 {
		local bn "3_1020y"
	}
	if `ii' == 6 {
		local bn "4_20py"
	}	
	
	#delimit ;

	* trendlines;
	reg de lcgdp if ebin == `ii';
	predict trend_t;

	* tenure ;
	twoway(scatter de AGDP, mcolor("`color1b'%10") msize(`msize1')  msymbol(O) mlwidth(none)) 
	(line trend_t AGDP, lcolor(gs6) lwidth(thin) alc(background)) 
	(scatter dae2 mean_AGDP if counter == 1, mcolor("`color1'") msize(`msize2') mlabel(ccode) msymbol(O) mlabcolor("`color1'")) 
	if ebin == `ii' & de >= 0, name(WageGrowth_e`ii') legend(off) graphregion(color("`colorgb'")) xtitle("GDP per capita") 
	yscale(r(0 80)) ylabel(0(20)80) xscale(log) xlabel(4000 8000 16000 32000 64000);	
	#delimit cr
	if `ii' >= 5 {
		graph export "Figures/Figure7_ExperBin`bn'.tif", replace
		graph export "Figures/pdf_figures/Figure7_ExperBin`bn'.pdf", replace
		
	}
	drop trend_t

}
